package com.banmajio.service;

import com.banmajio.entity.VolunteerInfo;
import com.banmajio.pojo.VolunteerTrajectory;
import com.banmajio.pojo.YoungsterInfo;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 数据清洗服务接口
 */
public interface DataCleanningService {

    /**
     * 从源数据库获取数据
     */
    List<Map<String, Object>> fetchDataFromSource(String tableName);

    @DS("slave")
    List<Map<String, Object>> fetchDataByPage(String tableName, String pageNum, long pageSize);

    /**
     * 清洗数据
     */
    List<Map<String, Object>> cleanData(List<Map<String, Object>> rawData);

    /**
     * 将清洗后的数据存入目标数据库
     */
    boolean saveCleanedData(List<VolunteerInfo> cleanedData, String targetTable);

    /**
     * 执行完整的数据清洗流程
     */
    void executeDataCleanProcess(String sourceTable, String targetTable) throws InterruptedException;

    @DS("master")
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    boolean saveCleanedDataYoung(List<YoungsterInfo> youngsterInfoList, String youngsterInfo);


    @DS("master")
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    boolean saveCleanedDataTrajectory(List<VolunteerTrajectory> youngsterInfoList, String youngsterInfo);
}